﻿/* Autoduel Game
 * CS4911 Senior Design Project
 * Fall 2010 Semester
 * Ian Axelrod, Liz Ha, Andrew Muldowney, Edward Futch
 */
using AutoduelClient.GameClient.Network;
using System;
namespace AutoduelClient.GameClient
{
    /// <summary>
    /// Represents the body of a car in Autoduel
    /// </summary>
    public class Chassis
    {
		#region Fields (5)
		// the available spaces of this chassis
        private int availableSpaces;
		// the cost of this chassis
        private int costMod;
		// the weight of this chassis
        private int weightMod;

		// the image associated with this chassis
        private string image;
		// the name of this chassis
        private string name;
		#endregion

		#region Properties (5)
		/// <summary>
        /// Gets/Sets the available spaces of this chassis
        /// </summary>
        public int AvailableSpaces
        {
            get { return availableSpaces; }
            set { availableSpaces = value; }
        }
		/// <summary>
        /// Gets/Sets the cost of this chassis
        /// </summary>
        public int CostMod
        {
            get { return costMod; }
            set { costMod = value; }
        }
		/// <summary>
        /// Gets/Sets the image associated with this chassis
        /// </summary>
        public string Image
        {
            get { return image; }
            set { image = value; }
        }
		/// <summary>
        /// Gets/Sets the name of this chassis
        /// </summary>
        public string Name
        {
            get { return name; }
            set { name = value; }
        }
		/// <summary>
        /// Gets/Sets the weight of this chassis
        /// </summary>
        public int WeightMod
        {
            get { return weightMod; }
            set { weightMod = value; }
        }
		#endregion

        /// <summary>
        /// Construct a chassis object from the provided packet
        /// </summary>
        /// <param name="packet">The packet to construct the chassis from</param>
        /// <returns>The constructed chassis</returns>
        public static Chassis DecodePacket(byte[] packet)
        {
            int i = 1;
            Chassis chassis = new Chassis();

            chassis.AvailableSpaces = 0; // not implemented
            chassis.Image = ""; // not implemented

            chassis.Name = Util.MakeString(packet, ref i);
            chassis.CostMod = Util.ReverseInt32(BitConverter.ToInt32(packet, i));
            chassis.WeightMod = Util.ReverseInt32(BitConverter.ToInt32(packet, i + 4));
            i += 8;
            chassis.Image = Util.MakeString(packet, ref i);

            return chassis;
        }

        /// <summary>
        /// Returns a string representation of the shassis
        /// </summary>
        /// <returns>The string representation of this chassis</returns>
        public override string ToString()
        {
            return this.name;
        }
    }
}
